from django.db import models

# Create your models here.

class UserGroup(models.Model):
    title = models.CharField(max_length=32)

class UserInfo(models.Model):
    user_type_choice = (
        (1,'普通用户'),
        (2,'vip'),
        (3,'svip')
    )

    user_type = models.IntegerField(choices=user_type_choice)
    group = models.ForeignKey(UserGroup,on_delete=models.CASCADE)
    username = models.CharField(max_length=32)
    password = models.CharField(max_length=32)

class UserToken(models.Model):
    user = models.OneToOneField(to='UserInfo',on_delete=models.CASCADE)
    Token = models.CharField(max_length=64)

class Role(models.Model):
    title = models.CharField(max_length=32)


class IpAddressUseInfo(models.Model):
    ipaddr = models.GenericIPAddressField(unique=True,null=True)
    def __str__(self):
        return self.ipaddr
    class Meta:
        verbose_name_plural = verbose_name = "IP地址"

class VlanManageInfo(models.Model):
    vlan = models.CharField(max_length=8,null=True)
    def __str__(self):
        return self.vlan
    class Meta:
        verbose_name_plural = verbose_name = "VLAN管理"


class Phone(models.Model):
    numbers = models.IntegerField()
    ipaddr = models.OneToOneField(IpAddressUseInfo,on_delete=models.CASCADE)
    vlan = models.ForeignKey(VlanManageInfo,on_delete=None)
    is_active = models.BooleanField(default=True)
    def __str__(self):
        return str(self.numbers)
    class Meta:
        verbose_name_plural = verbose_name = "电话"


class Computer(models.Model):
    names = models.CharField(max_length=8,default="默认")
    ipaddr = models.OneToOneField(IpAddressUseInfo,on_delete=models.CASCADE)
    vlan = models.ForeignKey(VlanManageInfo,on_delete=None)
    class Meta:
        verbose_name_plural = verbose_name = "电脑"


